﻿
<!-- BEGIN:main -->

<script language="javascript" type="text/javascript">

    var id_gia_soluong =new Array();
    <!-- BEGIN:hanghoas_gia_soluong -->
    id_gia_soluong[id_gia_soluong.length] = {H_ID};
    <!-- END:hanghoas_gia_soluong -->
    
    
    


  
       function addTong(){
   
        window.history.back(2);
         var tong=0;
         for (var i=0; i<id_gia_soluong.length;i++){ 
             
            tong=tong+ $('#DON_GIA_'+id_gia_soluong[i]).val()*$('#SOLUONG_'+id_gia_soluong[i]).val()
             
           
       }
         
        $('#NHAP_TONG_TIEN_PHAI_TRA').val(tong);
        }
       
     
     
     var hinhthucthanhtoan='';
     function addhinhthucthanhtoan(id){
     
          hinhthucthanhtoan=id;
       }
     
     function TestChonHang(){
         var NHAP_TONG_TIEN_PHAI_TRA=$('#NHAP_TONG_TIEN_PHAI_TRA');
         var arrayInput1 = new Array(NHAP_TONG_TIEN_PHAI_TRA);
          var hasError1 = validateEmptyValue(arrayInput1);
          if (hasError1) {
            alert('Vui lòng chọn hàng hóa nhập');
        }else{
            $("#popupDialog1").popup('open');
        }
     }
     
     
     
     
    function submitNhap(action)
    {

    if(action=='cancel'){
        window.history.back(2);
    }else{
         var BEP_ID = $('#BEP_ID');
         var NHAP_NGAY_NHAP = $('#NHAP_NGAY_NHAP');
         var NHAP_TONG_TIEN_PHAI_TRA=$('#NHAP_TONG_TIEN_PHAI_TRA');
         var LY_DO_NHAP=$('#LY_DO_NHAP');
          var prices=new Array();
          var soluong=new Array();
          var thanhtien=new Array();
          var id_hanghoa=new Array();
         for (var i=0; i<id_gia_soluong.length;i++){ 
             
             if( ($('#DON_GIA_'+id_gia_soluong[i]).val()*$('#SOLUONG_'+id_gia_soluong[i]).val())!=0 ){
                 prices[prices.length] = $('#DON_GIA_'+id_gia_soluong[i]).val();
                  soluong[soluong.length] = $('#SOLUONG_'+id_gia_soluong[i]).val();
                  thanhtien[thanhtien.length] = $('#DON_GIA_'+id_gia_soluong[i]).val()*$('#SOLUONG_'+id_gia_soluong[i]).val();
                  id_hanghoa[id_hanghoa.length] = id_gia_soluong[i];
             
        }
             
           
           
       }
         
         if(hinhthucthanhtoan==''){
             hinhthucthanhtoan=1;
             
         }
         var arrayInput = new Array(NHAP_NGAY_NHAP);
        var hasError = validateEmptyValue(arrayInput);
       
        if (hasError) {
            alert('Vui lòng điền đầy đủ dữ liệu');
        } else {
        var dataString = 'hdAction=' + action;
        dataString += '&BEP_ID=' + BEP_ID.val();
        dataString += '&NHAP_NGAY_NHAP=' + NHAP_NGAY_NHAP.val();
          dataString += '&NHAP_TONG_TIEN_PHAI_TRA=' + NHAP_TONG_TIEN_PHAI_TRA.val();
          dataString += '&LY_DO_NHAP=' + LY_DO_NHAP.val();
          dataString += '&DON_GIA=' + prices;
          dataString += '&SOLUONG=' + soluong;
          dataString += '&THANHTIEN=' + thanhtien;
          dataString += '&ID_HH=' + id_hanghoa;
           dataString += '&hinhthucthanhtoan=' + hinhthucthanhtoan;
          
        
        $.ajax({
            url: '.?com=com_logic_nhap&task=add',
            type: "POST",
            data: dataString,
            cache: false,
            success: function(data) {
//                alert(data);
                if (data.trim() == 'OK') {
                    alert('Thêm thành công');
                    window.location.href='.?com=com_logic_nhap';
                    
                }
            }
        });
        
            }
    }
       


    }
</script> 


<!--biến giá trị hành động-->


<div data-role="content">
   
        <h2><div class="header icon-48-article-add">
                        Phiếu nhập: <small><small>[ Thêm mới ]</small></small>
                    </div></h2>

        <form method="post" name="phpForm" id="phpForm" action="" class="ui-body ui-body-c ui-corner-all">
           
            <input type="hidden" name="hdAction" id="hdAction" />
            

            <div data-role="fieldcontain">
                <label for="name-c" class="select" style=" width:150px;display: inline-block; ">Bếp:</label>
                <select name="BEP_ID" id="BEP_ID" data-theme="c" data-overlay-theme="d" data-native-menu="false">
                    <!-- BEGIN:bep --> 
                    <option value="{BEP_ID}">{BEP_TEN_BEP}</option>
                    <!-- END:bep -->
                </select>
            </div>
            
          <div data-role="fieldcontain" >
                <label for="name-c" style=" width:150px;display: inline-block; ">Ngày nhập:</label>
                <input type="date" name="NHAP_NGAY_NHAP" id="NHAP_NGAY_NHAP" value="{DATE}">
                <!--<input type="date" name="NHAP_NGAY_NHAP" id="NHAP_NGAY_NHAP"  value="{DATE}" />-->
            </div>
            <div data-role="fieldcontain" >
                <label for="name-c" style=" width:150px;display: inline-block; ">Lý do nhập:</label>
               <textarea cols="40" rows="10" name="LY_DO_NHAP" id="LY_DO_NHAP">Nhập nguyên liệu</textarea>
            </div>
            <div data-role="fieldcontain" >
                <label for="name-c" style=" width:150px;display: inline-block; ">Nhập hàng:</label>
                <a href="#popupLogin" data-rel="popup" data-position-to="window" data-role="button" data-inline="true" data-icon="add" data-theme="c" data-transition="pop">Chọn hàng hóa nhập</a>
                <div data-role="popup" id="popupLogin" data-theme="b" class="ui-corner-all">
                   
                        <div style="padding:10px 20px;">
                             <h3><div class="header icon-48-article-add">
                        Hàng hóa: <small><small>[ Nhập ]</small></small>
                    </div></h3>
                             
                             <!-- BEGIN:hanghoa -->

							 
							 <div data-role="collapsible" data-inset="false" data-theme="b" >
								<h3 style="padding-top: 0px;">{H_TEN}</h3>
								<ul data-role="listview">
									
									<li>
									<div data-role="fieldcontain" >
                        <label for="name-c" style=" width:150px;display: inline-block; ">Đơn giá (VNĐ):</label>
                        <input type="text" name="DON_GIA_{H_ID}" id="DON_GIA_{H_ID}" value="{H_GIA_NHAP}"  />
                    </div>
                      
                        <label for="name-c" style=" width:150px;display: inline-block; ">Số lượng:</label>
                        <input name="SOLUONG_{H_ID}"  id="SOLUONG_{H_ID}" data-highlight="true" min="0" max="1000" value="0" type="range">
                            
									</li>                         
									
								</ul>
							</div>

                       <!-- END:hanghoa -->
                             
                        </br>
                    <div class="ui-body ui-body-b">
                      
                                <a href="javascript:void()" onclick="addTong();" data-role="button"  data-theme="b">
                                    Đồng ý</a>
                            
                    </div>
                        </div>
                   
                </div>
               
            </div>
            
            
            <div data-role="fieldcontain" >
                <label for="name-c" style=" width:150px;display: inline-block; ">Tổng tiền phải trả (VNĐ):</label>
                <input disabled="disabled" type="text" name="NHAP_TONG_TIEN_PHAI_TRA" id="NHAP_TONG_TIEN_PHAI_TRA" value=""  />
            </div>
            <div class="ui-body ui-body-b">
                <fieldset class="ui-grid-a">
                    <div class="ui-block-a">
                        <a href="javascript:void()" onclick="submitNhap('cancel');" data-role="button"  data-theme="c">
                            Cancel</a>
                    </div>
                    <div class="ui-block-b">
                       
                        <a data-rel="popup" onclick="TestChonHang();" data-position-to="window" data-transition="pop"  data-role="button" data-theme="b">Lưu</a>
                       
                        <div data-role="popup" id="popupDialog1" data-overlay-theme="a" data-theme="c" data-dismissible="false" style="max-width:400px;" class="ui-corner-all">
                        <div data-role="header" data-theme="a" class="ui-corner-top">
                            <h1>Thông báo</h1>
                        </div>
                        <div data-role="content" data-theme="d" class="ui-corner-bottom ui-content">
                            <h3 class="ui-title">Chọn hình thức thanh toán ?</h3>
                            <p> <fieldset data-role="controlgroup" data-type="horizontal">
                            
                            <input onchange="addhinhthucthanhtoan(this.value);" name="radio-choice-h-2" id="radio-choice-h-2a" value="1" checked="checked" type="radio">
                            <label for="radio-choice-h-2a">Tiền mặt</label>
                            <input onchange="addhinhthucthanhtoan(this.value);" name="radio-choice-h-2" id="radio-choice-h-2b" value="0" type="radio" disabled="true">
                            <label for="radio-choice-h-2b">Công nợ</label>
                        </fieldset></p>
                            <a href="#" data-role="button" data-inline="true" data-rel="back" data-theme="c">Bỏ qua</a>
                            <a href="javascript:void()" onclick="submitNhap('add');" data-role="button" data-inline="true" data-rel="back" data-transition="flow" data-theme="b">Đồng ý</a>
                        </div>
                    </div>
                        
                    </div>
                    
                </fieldset>
            </div>
        </form>

  




</div>
<div data-role="footer" data-theme="b" data-position="fixed">
    <div class="ui-bar">
        <a href="./?com=com_logic_nhap" data-role="button" data-icon="refresh" data-theme="b" style="float:left;">Trở lại</a>
        <!--<a href="javascript:void()" onclick="submitForm11('remove');" data-role="button" data-icon="delete" data-theme="b" style="float:right;" class="returnTopAction">Xóa</a>-->             
    </div>
</div>   



<!-- END:main -->
